﻿@using DTcms.Common;
@{
    ViewBag.Title = "管理员列表";
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="../users/user_list" class="back"><i class="fa fa-mail-reply-all"></i> 返回列表页</a></li>
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">编辑会员</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a data-type="btnAdd" class="layui-btn icon-btn layui-btn-normal layui-btn-sm" href="../manager/manager_edit?action=@DTEnums.ActionEnum.Add"><i class="iconfont icon-close1"></i> 新增</a>
                            <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i> 删除</a>
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'user_name',templet:'#usernameTpl'}">用户名</th>
                        <th lay-data="{field:'real_name'}">姓名</th>
                        <th lay-data="{field:'roleTitle'}">角色</th>
                        <th lay-data="{field:'telephone'}">电话</th>
                        <th lay-data="{field:'add_time'}">添加时间</th>
                        <th lay-data="{field:'is_lock',templet: '#switchTpl'}">状态</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="barDemo">
    <a href="../manager/manager_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs">修改</a>
</script>
<script type="text/html" id="usernameTpl">
    <a href="../manager/manager_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-table-link">{{ d.user_name }}</a>
</script>
<script type="text/html" id="roleTpl">
    {{role_title(d.role_id)}}
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="is_lock" value="{{d.id}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="lock" {{ d.is_lock == 0 ? 'checked' : '' }}>
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['table','cmswh'], function () {
            var table = layui.table, form = layui.form, cmswh = layui.cmswh, $ = layui.jquery;

            cmswh.dataBind('ManagerList');
            //监听状态操作
            form.on('switch(lock)', function (obj) {
                cmswh.request("ManagerLock", "POST", { id: this.value, is_lock: obj.elem.checked });
            });
            var active = {
                btnDelete: function () {
                    cmswh.batOperate('ManagerDelete', 'id');
                },
                btnSearch: function () {
                    //执行重载
                    table.reload('ltable', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: getcond()
                    });
                }
            };
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var postdata = { keywords: keywords };
                return postdata;
            }
        });
    </script>
}